#TTT file:
#Contains basic program manipulation and is the main executable

#Fully import everything

from Exc import *
##from Grid import *
from AI import *
from InOut import *
from Logfile import *

#Create an empty table and log file
##table=Grid()
table=Log()


#Fxn gives basic flow control
def Flow():

    print '\n\n\nWelcome to Tic-Tac-Totality...\nTo exit the program, just do something you shouldn\'t!\n'

    try:
    
        #Find out who is going first
        AskPerson(table)

        #If the person wants to, let them!
        if table.Human == 'X':


            table.Display()
            AskTurn(table)

            
        #Start game loop
        while 1 == 1:

            #Comp makes its move
            print '\n\n\nThe computer is making its move...\n'
            y, x = MakeMove(table)
            table.Move(table.Comp, y, x)

            #Check for win and Cat's Game
            table.CheckWin()
            table.CatsGame()

            table.Display()

            #Have human make move
            AskTurn(table)

            #Check for win and Cat's Game
            table.CheckWin()
            table.CatsGame()

            table.Display()


    except Winner:

        table.Display()
        print "\nWinner - Game Over!"

        table.Save('Winner')

    except IllegalMove:

        print "Illegal move made"

        table.Save('IllegalMove')


    except CatsGame:

        table.Display()
        print "\nCat's Game"

        table.Save('CatsGame')


    except IllegalRep:

        print "Illegal choice of character representation"

        table.Save('IllegalRep')

    except ExitProg:

        raise ExitProg

    except:

        table.Save('Built-in exception')



if __name__ == '__main__':

    while 1:
        Flow()



